home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRDUPL.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  1KB  |  86 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7.         extrn    sl_malloc:far
  8. ;
  9. ;
  10. ; strdupl- Copies string pointed at by cs:rtnadrs to heap and returns a
  11. ;       pointer to this new string in es:di.
  12. ;
  13. ;
  14. ; inputs:
  15. ;        cs:rtn-    Zero-terminated source string.
  16. ; outputs:
  17. ;        es:di-    Points at destination string on heap.
  18. ;
  19. ;
  20. ;
  21.         public    sl_strdupl
  22. ;
  23. rtnadrs        equ       2[bp]
  24. ;
  25. sl_strdupl    proc    far
  26.         push    bp
  27.         mov    bp, sp
  28.         push    ds
  29.         push    cx
  30.         push    ax
  31.         pushf
  32.         push    si
  33. ;
  34.         cld
  35.         mov    al, 0
  36.         mov    cx, 0ffffh
  37.         les    di, rtnadrs
  38.     repne    scasb
  39.         lds    si, rtnadrs
  40.         mov    rtnadrs, di
  41.         neg    cx
  42.         dec    cx
  43. ;
  44. ; Allocate some storage for the string.
  45. ;
  46.         push    cx            ;Save for later
  47.         call    sl_malloc
  48.         pop    cx
  49.         jc    BadStrDupl
  50. ;
  51.         push    es            ;Save ptr to string
  52.         push    di
  53. ;
  54. ; Copy the string to the new space on the heap.
  55. ;
  56.         shr    cx, 1
  57.         jnc    CpyWrd
  58.         lodsb
  59.         stosb
  60. CpyWrd:    rep    movsw
  61.         pop    di            ;Restore pointer to string.
  62.         pop    es
  63. ;
  64. DidByte:    pop    si
  65.         popf
  66.         pop    ax
  67.         pop    cx
  68.         pop    ds
  69.         pop    bp
  70.         clc
  71.         ret
  72. ;
  73. BadStrDupl:    pop    si
  74.         popf
  75.         pop    ax
  76.         pop    cx
  77.         pop    ds
  78.         pop    bp
  79.         stc
  80.         ret
  81. sl_strdupl    endp
  82. ;
  83. ;
  84. stdlib        ends
  85.         end
  86.